package com.alibaba.algo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author : WangZhiPan
 * @date : 2021/11/12 15:00
 */
@AllArgsConstructor
public enum SysOrgStateEnum {
    EFFECTIVE(1L, "有效"),
    INEFFICIENCY(0L, "无效");;
    @Getter
    private Long value;
    @Getter
    private String name;


    /**
     * 判断组织状态
     *
     * @param status
     * @param startTime
     * @param endTime
     * @return
     */
    public static Long judgeStatus(Long status, Date startTime, Date endTime) {
        Long inefficiency = SysOrgStateEnum.INEFFICIENCY.getValue();
        Long effective = SysOrgStateEnum.EFFECTIVE.getValue();
        if (inefficiency.equals(status)) {
            return inefficiency;
        }
        Long now = System.currentTimeMillis();
        Long start = startTime.getTime();
        Long end = endTime.getTime();
        if (now.compareTo(start) >= 0 && now.compareTo(end) <= 0) {
            return effective;
        }
        return inefficiency;
    }
}
